package com.sinodata.bsm.cicp.collector;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

/**
 * 
 * <p>
 * Description: 
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-5-18 PM 5:37:01    liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see
 */
public class ResultSetProxy implements InvocationHandler {

    ResultSet resultSet;

    public ResultSetProxy(ResultSet resultSet) {
        this.resultSet = resultSet;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if ("getMetaData".equals(method.getName())) {
            ResultSetMetaData resultSetMetaData = (ResultSetMetaData) Proxy.newProxyInstance(ResultSetProxy.class.getClassLoader(), new Class[] { ResultSetMetaData.class }, new ResultSetMetaDataProxy(resultSet.getMetaData()));
            return resultSetMetaData;
        }
        return method.invoke(resultSet, args);
    }

}
